package team.zero.lemon.module.sys.service;

import team.zero.lemon.common.exception.CustomException;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.security.session.model.Function;
import team.zero.lemon.common.service.CrudService;
import team.zero.lemon.module.sys.dao.IFunctionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by bolin on 2016/5/10.
 */
@Service
public class FunctionService extends CrudService<IFunctionDao, Function> {
    @Autowired
    private IFunctionDao functionDao;

    public List<Function> findFunction(Function function) {
        try {
            return functionDao.findList(function);
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }

    public Page<Function> findFunctionByParentId(Function function) {
        try {
            List<Function> functions = functionDao.findPage(function);
            function.page.setList(functions);
            return function.page;
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }

}
